﻿namespace keyGame
{
    enum Key
    {
        w, a, s, d
    }
    class Program
    {
        static void Main(string[] args)
        {
            Random random = new Random();
            Console.WriteLine("请输入需要测试的次数");
            int frequency = Convert.ToInt32(Console.ReadLine());
            Console.Clear();
            int[] keys = new int[frequency];
            //在随机位置读取一个数并保存到数组中
            for (int i = 0; i < keys.Length; i++)
            {
                int RandomNumber = random.Next(0, 4);
                keys[i] = RandomNumber;
            }
            //记录错误次数
            int Wrongnumber = 0;
            //开始时间 
            DateTime StarTime = DateTime.Now;
            for (int i = 0; i < frequency; i++)
            {              
                Key key = (Key)keys[i];
                //屏幕上输出需要输入的字母
                Console.WriteLine(key);
            beforeinput:
                //记录输入的字母
                ConsoleKey input = Console.ReadKey().Key;
                //换行
                Console.Write('\n');
                //判断输入字母
                switch (key)
                {
                    case Key.w:
                        if (input ==ConsoleKey.W )
                        {
                            Console.Clear();
                        }
                        else
                        {
                            Wrongnumber++;
                            Console.WriteLine("请重新输入 当前错误次数为" + Wrongnumber+ "次");
                            //重新输入
                            goto beforeinput;
                        }
                        break;
                    case Key.a:
                        if (input == ConsoleKey.A)
                        {
                            Console.Clear();
                        }
                        else
                        {
                            Wrongnumber++;
                            Console.WriteLine("请重新输入 当前错误次数为"+ Wrongnumber+"次");
                            //重新输入
                            goto beforeinput;
                        }
                        break;
                    case Key.s:
                        if (input == ConsoleKey.S)
                        {
                            Console.Clear();
                        }
                        else
                        {
                            Wrongnumber++;
                            Console.WriteLine("请重新输入 当前错误次数为" + Wrongnumber+ "次");
                            //重新输入
                            goto beforeinput;
                        }
                        break;
                    case Key.d:
                        if (input == ConsoleKey.D)
                        {
                            Console.Clear();
                        }
                        else
                        {
                            Wrongnumber++;
                            Console.WriteLine("请重新输入 当前错误次数为" + Wrongnumber+ "次");
                            //重新输入
                            goto beforeinput;
                        }
                        break;
                }
                




            }
            //计算相差时间
            DateTime EndTime = DateTime.Now;
            TimeSpan span = EndTime - StarTime;
            int Span = span.Seconds;
            Console.WriteLine($"总耗时{Span}秒，总的错误次数为{Wrongnumber}次");
            Console.ReadKey();



        }
    }
}